/*!
// Testweb v0.3.0
// http://or-change.cn
// Copyright 2014 OrChange Inc. All rights reserved.
// Licensed under the GPL License.
*/
/*jslint vars: true, forin: true, plusplus: true */
/*global define: false */
define(function (require, exports, module) {
	'use strict';
	var helper = require("model/helper"),
		jQuery = require("lib/jquery/jquery");
	exports.execute = function (me, $, load) {
		return function () {
			helper.moveToCenter(me);
			helper.initWindowTemplate(me);

			$("#create").click(function () {
				var data, options = {},
					form = $("form").serializeObject();

				form.maxLoops = parseInt(form.maxLoops, 0);
				if (form.dict_ID) {
					form.dictionary = load.dict.getDictionary(parseInt(form.dict_ID.match(/\:(\d+)/)[1], 0));
				}
				load.ppm.create(form);

				// 给ui面板准备的数据
				data = load.ppm.getProgramList();
				data.process_name = form.name;

				// 刷新ui
				load.tpm.refresh("ui", data);
				load.tpm.close(me);
			});

			$("#modify").click(function () {
				var data, options = {},
					form = $("form").serializeObject();

				form.maxLoops = parseInt(form.maxLoops, 0);
				if (form.dict_ID) {
					form.dictionary = load.dict.getDictionary(parseInt(form.dict_ID.match(/\:(\d+)/)[1], 0));
				}
				load.ppm.modify(form);

				// 给ui面板准备的数据
				data = load.ppm.getProgramList();
				data.process_name = form.name;

				// 刷新ui
				load.tpm.refresh("ui", data);
				load.tpm.close(me);
			});
			$("#catch").click(function () {
				var location;
				location = jQuery("iframe").get(0).contentWindow.location.href;
				$("#origin").val(location);
			});

			$("#open-dict").click(function () {
				var form = $("form").serializeObject();
				load.tpm.refresh(me, {
					form: form
				}).open("dictionary_open", {
					local: load.dict.getDictionaryList()
				});
			});
		};
	};
});